import java.util.Scanner;
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: GodK
 * Date: 2024-07-28
 * Time: 20:02
 */
public class Test {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        for(int i = 0;i < t;i++){
            int n = in.nextInt();
            int k = in.nextInt();
            in.nextLine();
            char[] arr = in.nextLine().toCharArray();
//            String str = in.nextLine();
//            char[] arr = str.toCharArray();
            int ret = 0;
            boolean[] dp = new boolean[n];
            if(arr[0] == 'W'){
                dp[0] = true;
                ret++;
            }
            if(arr[1] == 'W'){
                dp[1] = true;
                ret++;
            }
            for(int j = 2;j < n;j++){
                if(arr[j] == 'W')dp[j] = true;
                else {
                    ret--;
                    continue;
                }
                if(dp[j-1] && dp[j-2] && dp[j])ret+=k;
                else ret++;
                System.out.println(ret);
            }
        }
    }
}
